<?php
include dirname(dirname(dirname(__FILE__))).'/include/user-verify.php';
include dirname(dirname(__FILE__)).'/user-manage/functions.php';

$id = addslashes($_SESSION['user_id']);
$row = getUserById($id);
$arr = json_decode($row['available_time'],true);
?>

<!DOCTYPE html>
<html>
	<head>
		<?php include dirname(dirname(dirname(__FILE__))).'/include/common-header.php'; ?>

		<script type="text/javascript">
		$(document).ready(function() {
			$("input").attr("maxlength","16");
			<?php if($row['is_user_on_duty']==1)echo '
				$("#is_user_on_duty").attr("checked","checked");
				';
			?>
		});
		</script>

		<link rel="stylesheet" type="text/css" href="../css/style.css">
	</head>
	<body>
		<div class="col-md-12">
			<div>
				<h3>修改 <?php echo $row['username']; ?> 的信息</h3>
			</div>
			<form class="form-horizontal" role="form" method="post" action="personal-info-submit.php">
			  <div class="form-group">
			    <label for="student_id" class="col-sm-2 control-label">学号</label>
			    <div class="col-sm-10">
			      <input type="text" name="student_id" class="form-control normal-input"
			      value=<?php echo '"'.$row['student_id'].'"'; ?> id="student_id" placeholder="学号">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="department" class="col-sm-2 control-label">学院</label>
			    <div class="col-sm-10">
			      <input type="text" name="department" class="form-control normal-input" 
			      value=<?php echo '"'.$row['department'].'"'; ?> id="department" placeholder="学院">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="grade" class="col-sm-2 control-label">年级</label>
			    <div class="col-sm-10">
			      <input type="text" name="grade" class="form-control normal-input"
			      value=<?php echo '"'.$row['grade'].'"'; ?> id="grade" placeholder="年级">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="user_real_name" class="col-sm-2 control-label">姓名</label>
			    <div class="col-sm-10">
			      <input type="text" name="user_real_name" class="form-control normal-input"
			      value=<?php echo '"'.$row['user_real_name'].'"'; ?> id="user_real_name" placeholder="姓名">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="sex" class="col-sm-2 control-label">性别</label>
			    <div class="col-sm-10">
			      <input type="text" name="sex" class="form-control normal-input" 
			      value=<?php echo '"'.$row['sex'].'"'; ?> id="sex" placeholder="性别">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="phone" class="col-sm-2 control-label">联系方式</label>
			    <div class="col-sm-10">
			      <input type="text" name="phone" class="form-control normal-input" 
			      value=<?php echo '"'.$row['phone'].'"'; ?> id="phone" placeholder="手机或电话">
			    </div>
			  </div>

			  <div class="form-group">
			    <label for="#" class="col-sm-2 control-label">可值班时间</label>
			    <div class="col-sm-10">
			        <table class="table table-striped table-bordered table-hover table-condensed " id="default-table">
					  <tr>
					  	<th>#</th>
					  	<th>星期一</th>
					  	<th>星期二</th>
					  	<th>星期三</th>
					  	<th>星期四</th>
					  	<th>星期五</th>
					  	<th>星期六</th>
					  	<th>星期天</th>
					  </tr>
					  <?php 
					  $time = array();
					  $time['a']='7:30~10:00';$time['b']='10:00~12:30';
					  $time['c']='12:30~14:30';$time['d']='14:30~16:00';
					  $time['e']='16:00~18:30';$time['f']='18:30~22:30';
					  foreach(range('a', 'f') as $item) {
					  	echo '<tr>';
					  	echo '<td>'.$time[$item].'</td>';
					  	for($i=1;$i<=7;$i++) {
					  		echo '<td>';
					  		echo '<input type="checkbox" name="'.$item.'_'.$i.'"';
					  		if($arr[$i][$item]=='1')echo 'checked="checked"';
					  		echo '>';
					  		echo '</td>';
					  	}
					  	echo '</tr>';
					  }
					  ?>
					  
					</table>
			    </div>
			  </div>

			  <?php
			  	if($_SESSION['user_role']=='super_admin') {
			  		echo '<div class="form-group">
						  <label for="is_user_on_duty" class="col-sm-2 control-label" >是否需要值班</label>
						    <div class="col-sm-10">
						      <div class="checkbox">
						        <label>
						          <input type="checkbox" id="is_user_on_duty" name="is_user_on_duty" value="1">需要值班
						        </label>
						      </div>
						    </div>
						  </div>';
			  	}
			  ?>
			  <div class="form-group">
			    <div class="col-sm-offset-2 col-sm-10">
			      <button type="submit" class="btn btn-primary" id="edit-user-btn">确认修改</button>
			    </div>
			  </div>
			</form>			
		</div>
	</body>
</html>